package cn.pay.view;

import cn.mtpay.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 支付类别帮助类
 *
 */
public class PayMethodListItem  extends BaseAdapter {

    private Integer[] payIcons;
    private String[] payNames;
    private String[] payDescs;
    private LayoutInflater mInflater;
    public PayMethodListItem(Context context, Integer[] payIcons, String[] payNames,
                             String[] payDescs) {
        this.payIcons = payIcons;
        this.payNames = payNames;
        this.payDescs = payDescs;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        if (payIcons == null)
            return 0;

        return payIcons.length;
    }

    @Override
    public Object getItem(int position) {
        return payNames[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final ViewHolder viewHolder;

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.pay_list_item, null);

            viewHolder = new ViewHolder();

            viewHolder.payIcon = (ImageView) convertView
                    .findViewById(R.id.payIcon);
            viewHolder.payName = (TextView) convertView
                    .findViewById(R.id.payName);
            viewHolder.payDesc = (TextView) convertView
                    .findViewById(R.id.payDesc);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        
        
        viewHolder.payIcon.setImageResource(payIcons[position]);
        viewHolder.payName.setText(payNames[position]);
        viewHolder.payDesc.setText(payDescs[position]);
        return convertView;
    }

    private class ViewHolder {
        public ImageView payIcon;
        public TextView payName;
        public TextView payDesc;
    }
}

